﻿using FireBillBook.Core.Dtos;
using FireBillBook.Core.Models;
using FireBillBook.Core.Models.QueryContexts;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using FireBillBook.Core.Repos;
using AutoMapper;

namespace FireBillBook.Core.Services
{
    public class BillingService : IBillingService
    {
        private IConsumptionRecordRepo _repo;
        private IMapper _mapper;

        public BillingService(IConsumptionRecordRepo repo, IMapper mapper)
        {
            _repo = repo;
            _mapper = mapper;
        }

        public async Task DeleteAsync(int id)
        {
            await _repo.DeleteAsync(id);
        }

        public async Task<ConsumptionRecordDto> GetByIdAsync(int id)
        {
            var record = await _repo.GetByIdAsync(id, true);
            return _mapper.Map<ConsumptionRecordDto>(record);
        }

        public async Task<PagingModel<ConsumptionRecordDto>> ListAsync(ConsumptionRecordListQueryContext queryContext)
        {
            return await _repo.ListAsyc(queryContext, true);
        }

        public async Task SaveAsync(ConsumptionRecordDto dto)
        {
            await _repo.SaveAsync(dto);
        }
    }
}
